home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / mac_file / vendor_d / neuralwa / nw2v50 / som.ind < prev    next >
File List  |  1993-08-23  |  9KB  |  460 lines

  1. inst4.1
  2. !****************************************************************
  3. !*                                *
  4. !*    Self Organizing Map                    *
  5. !*                                *
  6. !****************************************************************
  7. !
  8.  
  9. ?&In    2
  10. >bge    InOK
  11. @Err    "Network MUST have at least two input PE's"
  12. :InOK
  13.  
  14. ?SMnr    1
  15. >bge    RowOK
  16. @Err    "Self Organizing layer MUST have at least 1 row of PE's"
  17. :RowOK
  18.  
  19. ?SMnc    1
  20. >bge    ColOK
  21. @Err    "Self Organizing layer MUST have at least 1 column of PE's"
  22. :ColOK
  23.  
  24. ?SMmp    0
  25. >beq    NotMap1
  26.  
  27. ?&Out    1
  28. >bge    OutOK
  29. @Err    "Output Layer MUST have at least 1 PE for network map option"
  30. :OutOK
  31.  
  32. !    *** Load the Control Strategy and any fixed schedules ***
  33. @LdCS    "sommap"        !load mapping control strategy
  34.  
  35. ?BPLf    "Delta-Bar-Delta"    !DBD?
  36. >bne    NotDBD1            !Branch to next test if not
  37. @NLRS    "somdbd"
  38. #Incl    "somdbd.iif"        !special DBD schedule with 0 first col.
  39. =GrLF    "somdbd"        !instrument list file
  40. >br    LdStyle            !Continue
  41. :NotDBD1
  42. ?BPLf    "Ext DBD"        !EDBD
  43. >bne    NotEDBD1        !Branch if not
  44. @NLRS    "somedbd"
  45. #Incl    "somedbd.iif"        !special EDBD schedule with 0 first col.
  46. =GrLF    "somedbd"        !instrument list file
  47. >br    LdStyle
  48. :NotEDBD1
  49. =GrLF    "sombp"            !instrument list file
  50. =BBMm    0.4            !Assume momentum of 0.4
  51. >br    LdStyle
  52.  
  53. :NotMap1
  54. =GrLF    "som"            !instrument list file
  55. @LdCS    "somnomap"        !Load non-mapping control strategy
  56.  
  57. :LdStyle
  58. ! Load the style sheet
  59. @LdSt    "som"            !som control strategy
  60.  
  61. =netn    "Untitled"
  62. =DLnF    0            !learn  re-display off
  63. =DRcF    0            !recall re-display off
  64.  
  65. !    *** Build the Input Layer ***
  66.  
  67. @LLdf                !load default layer to mi_layer structure
  68. =LDln    "In"            !layer name
  69. =Lpes    &In            !copy # of input PEs from menu
  70. =Ltrn    "Linear"        !buffer
  71. =x    100            !place to put layer on screen
  72. =y     40
  73. @LDfW                !Default # weight fields
  74. @LAdd                !add the input layer
  75.  
  76. =n6    LayN            !input layer number
  77.  
  78. !    *** Build the 2-D Kohonen Layer ***
  79.  
  80. @LLdf                !start with default layer again
  81. =LDln    "2-D Kohonen"        !layer name
  82. =Lpes    SMnr
  83. *Lpes    SMnc            !number of PEs
  84. =LDnr   SMnr            !number of rows
  85. =LInL     -0.10            !Init low value
  86. =LInH    0.10            !Init high value
  87. =Lsum    "SOM"            !SOM summation function
  88. =Llrn    "SOM"            !SOM learning rule
  89. =Lcmp    "SOM"            !no output function required
  90. ! Build SOM schedule
  91. @NLRS    "som"
  92. #Incl    "somsched.iif"
  93. =Llrs    "som"
  94. +y    40            !up higher on display
  95. #Incl    "stdnwgtf.iif"        !standard # weight fields
  96. @LAdd
  97.  
  98. !    *** Connect Input Layer to Kohonen Layer ***
  99.  
  100. =SPEl    LayN            !2-D Kohonen layer
  101. @SlPE                !select it as destination 
  102. =NPEl    n6            !input layer
  103. @NrPE
  104. =cnwt    0.0            !connection weight
  105. =cnty    WVar            !variable
  106. =cnsc    WAbs            !absolute
  107. @LCFl                !fully connect to input layer
  108.  
  109. =n2    Lpes            !save for later
  110. =n5    LayN            !save for later
  111. =n6    LayN            !save for later
  112.  
  113. ! Set up position of any following layers
  114. ! Note: this assumes a special style sheet som.nns to
  115. ! make it look pretty
  116. =n0    SMnr
  117. *n0    20            !20 pixels for each SOM row
  118. +n0    20
  119. +y    n0            !move cursor up higher on display
  120.  
  121. ! coordinate layer?
  122. ?SMcd    0
  123. >beq    ChkMap
  124.  
  125. @LLdf                !start with default layer again
  126. =LDln    "Coords"        !layer name
  127. =Lpes    2            !Number of PEs
  128. =Lsum    "Sum"
  129. =Llrn    0            !No learn function
  130. =Lcmp    "Direct"
  131. =Ltrn    "Linear"
  132. =Lerf    "standard"
  133. =Llrs    "default"        !No learning params or noise
  134. @LDfW                !Default # weight fields
  135. @LAdd                !add the input layer
  136.  
  137. +y    40
  138.  
  139. ! Coordinate mapping is achieved by special fixed
  140. ! connection scheme
  141.  
  142. ! Col coords. -1.0 to 1.0
  143. ! f2 increment
  144. ?SMnc    2
  145. >blt    onecol
  146. =f0     SMnc
  147. -f0    1.0
  148. =f2    2.0
  149. /f2    f0
  150. :onecol
  151.  
  152. ! Row coords. -1.0 to 1.0
  153. ! f3 increment
  154. =f1    0.0
  155. ?SMnr    2
  156. >blt    onerow
  157. =f0     SMnr
  158. -f0    1.0
  159. =f3    2.0
  160. /f3    f0
  161. -f1    1.0
  162. :onerow
  163.  
  164. =f0    0.0
  165. ?SMnc    2
  166. >blt    onecol1
  167. -f0    1.0
  168. :onecol1
  169.  
  170. =n0    1            !first coordinate
  171. =n1    1            !second coordinate
  172. =n2    0            !PE count
  173.  
  174. =NPEl    n5            !SOM layer is source
  175. =SPEl    LayN            !coordinate layer is dest.
  176. =cnty    WFix            !fixed weights
  177. =cnsc    WRel            !Relative
  178.  
  179. :coordwts
  180.  
  181. =NPEn    n2            !set up source PE
  182. @NrPE
  183.  
  184. ! first coordinate
  185. =SPEn    0
  186. @SlPE
  187. =cnwt    f0
  188. @PCon                !PE connection
  189. ! second coordinates
  190. =SPEn    1
  191. @SlPE
  192. =cnwt    f1
  193. @PCon                !PE connection
  194.  
  195. +n2    1            !increment PE count
  196.  
  197. ! Increment column info
  198. +n0    1            !increment x-coord
  199. +f0    f2            !increment col coord.
  200.  
  201. ! Check for end of row
  202. ?n0    SMnc            !Compare to # cols
  203. >ble    coordwts        !in mid row, continue
  204.  
  205. ! We are at the end of a row. Reset count and coord.
  206. =n0    1            !reset column counter
  207. =f0    0.0            !reset x coord.
  208. ?SMnc    2
  209. >blt    onecol2
  210. -f0    1.0            !start at -1.0 unless 1 col
  211. :onecol2
  212.  
  213. ! Increment row info
  214. +f1    f3            !increment row coord
  215. +n1    1            !goto next row
  216. ?n1    SMnr            !Compare to # rows
  217. >ble    coordwts        !not at end yet
  218.  
  219. =n2    Lpes            !save for later
  220. =n5    LayN            !save for later
  221. =n6    LayN            !save for later
  222. =NPEn    0            !set up source PE
  223. =SPEn    0
  224.  
  225. :ChkMap
  226. ?SMmp    0
  227. >beq    NotMap2
  228.  
  229. ! Any hidden units?
  230. ?&Hd2    1
  231. >blt    NoHidden
  232.  
  233. @LLdf                !start with default layer again
  234. =LDln    "Hidden"        !layer name
  235. =Lpes    &Hd2            !Number of PEs
  236. =Lsum    "Sum"
  237. =Lcmp    "Direct"
  238. =Lerf    "standard"
  239. ?BPTf    "DNNA"            !Check for DNNA
  240. >bne    DNNA1
  241. =Lsum    "DNNA"            !DNNA summation
  242. :DNNA1
  243. =Ltrn    BPTf            !Transfer function
  244. =Llrn    BPLf            !Learning Rule
  245. !Use net global schedules for DBD and EDBD.  Create
  246. !schedules for others
  247. ?BPLf    "Delta-Bar-Delta"    !DBD?
  248. >beq    LRS2            !If yes, use net global
  249. ?BPLf    "Ext DBD"        !EDBD
  250. >beq    LRS2            !If yes, use net global
  251. =BBLC    H2LC            !Hidden 2 schedule
  252. @NLRS    LDln
  253. #Incl    "mapsched.iif"        !corrupts n0,n1,f0,f1,f2
  254. =Llrs    LDln            !Point to it
  255. :LRS2
  256. =f0    n2            !# PEs in previous layer
  257. #Incl    "wghtinit.iif"
  258. =LInH    f1
  259. =LInL    0.0
  260. -LInL    LInH            !-ve of high init limit
  261. =n2    Lpes            !#processing elements
  262. @LDfW                !Default # weight fields
  263. @LAdd
  264. +y    20            !increment for later
  265.  
  266. ! Now hook up previous layer
  267. =cnty    WVar            !Variable
  268. =cnsc    WRel            !Relative
  269. =SPEl    LayN            !Destination layer
  270. @SlPE
  271. =NPEl    n6            !Source layer
  272. @NrPE
  273. @LCFl                !Full Connections
  274.  
  275. ! Check if Bias desired
  276.  
  277. ?BPBi    0
  278. >ble    NoBias1
  279. =NPEl    -1
  280. @NrPE
  281. @LCFl                !Full Connections
  282.  
  283. :NoBias1
  284. =n6    LayN
  285. ?BPCP    0
  286. >bgt    NoHidden
  287. =n5    LayN
  288.  
  289. :NoHidden
  290.  
  291. ! Now build output layer
  292. @LLdf                !start with default layer again
  293. =LDln    "Out"            !layer name
  294. =Lpes    &Out            !Number of PEs
  295. =Lsum    "Sum"
  296. =Ltrn    "Linear"
  297. =Lcmp    "Direct"
  298. =Lerf    "standard"
  299. ?BPTf    "DNNA"            !Check for DNNA
  300. >bne    DNNA2
  301. =Lsum    "DNNA"            !DNNA summation
  302. =Ltrn    "DNNA"            !DNNA transfer
  303. >br    LinOut            !Don't use Linear Output for DNNA
  304. :DNNA2
  305. ! Not DNNA.
  306. =Ltrn    "Linear"        !Assume linear
  307. ?BPSM    0            !Softmax activation?
  308. >bgt    SoftMax1        !Linear output for SoftMax
  309. ?BPLi    0            !Linear Output?
  310. >bgt    LinOut            !yep
  311. =Ltrn    BPTf            !Transfer function
  312. >br    LinOut
  313. :SoftMax1
  314. ! Force following for SoftMax.
  315. =Lcmp    "SoftMax"
  316. =Lerf    "SoftMax"        !Does out-err instead of trn-err
  317. :LinOut
  318.  
  319. =Llrn    BPLf            !Learning Rule
  320. !Use net global schedules for DBD and EDBD.  Create
  321. !schedules for others
  322. ?BPLf    "Delta-Bar-Delta"    !DBD?
  323. >beq    LRS3            !If yes, use net global
  324. ?BPLf    "Ext DBD"        !EDBD
  325. >beq    LRS3            !If yes, use net global
  326. =BBLC    OPLC            !output learning coef.
  327. @NLRS    LDln
  328. #Incl    "mapsched.iif"        !corrupts n0,n1,f0,f1,f2
  329. =Llrs    LDln            !Point to it
  330. :LRS3
  331. =f0    n2            !# PEs in previous layer
  332. #Incl    "wghtinit.iif"
  333. =LInH    f1
  334. =LInL    0.0
  335. -LInL    LInH            !-ve of high init limit
  336. =n2    Lpes            !#processing elements
  337. @LDfW                !Default # weight fields
  338. @LAdd
  339.  
  340. =n7    LayN            !current layer index
  341.  
  342. ! Now do connections.
  343. =cnwt    1.0
  344. =cnty    WVar            !Variable
  345. =cnsc    WRel            !Relative
  346. ! Connect fully with variable weights
  347. ! n5 to n6 are source layers (n5=n6 if prior connections have
  348. ! not been requested).
  349. =SPEl    LayN
  350. @SlPE
  351. :MpLyrs
  352. =NPEl    n5
  353. @NrPE
  354. @LCFl                !Full Connections
  355. +n5    1
  356. ?n5    n6
  357. >ble    MpLyrs
  358. ! Now the bias
  359. ?BPBi    0
  360. >ble    NoBias2
  361. =NPEl    -1
  362. @NrPE
  363. @LCFl                !Full Connections
  364.  
  365. :NoBias2
  366.  
  367. ! Check-pointing
  368. ?BPTf    "DNNA"
  369. >bne    DNNA3
  370. =DLnN    1            !learn count for Check Points
  371. =MWLF    1            !turn on weight limiting
  372. =WtVl    0.99            !max value for weight limiting
  373. :DNNA3
  374.  
  375. :NotMap2
  376.  
  377. =LnPr    0            !no pruning
  378.  
  379. @LLsl                !load super layer
  380.  
  381. !
  382. ! I/O parameters:
  383. !
  384. =Llnn    "train"            !name of learn input
  385. =Lrcn    "test"            !name of recall output
  386. #Incl    "stdioset.iif"        !standard I/O settings
  387. =Lax1    Epch            !set epoch from dialog
  388. ! Target ranges for MinMax tables
  389. ! Set up default settings
  390. =Lscl    -1.0            !input  low-value
  391. =Loff    1.0            !input  high-value
  392. =Llow    0.0            !output low-value
  393. =Lhgh    1.0            !output high-value
  394. ?SMmp    0
  395. >beq    RngDone
  396. ?BPSM    0            !Softmax activation?
  397. >bgt    RngDone            !if yes,default settings are OK
  398. ! Set up defaults for mapping (Unipolar)
  399. =Llow    0.2            !output low-value
  400. =Lhgh    0.8            !output high-value
  401. ?BPTf    "DNNA"            !DNNA?
  402. >beq    RngDone            !Yes (Linear output not allowed)
  403. ! Linear output overrides transfer function
  404. ?BPLi    0            !Linear Output?
  405. >bne    BiPolar            !If yes, bipolar
  406. ?BPTf    "Sigmoid"        !Sigmoid?
  407. >beq    RngDone            !Yes
  408. ?BPTf    "Perceptron"        !Perceptron?
  409. >beq    RngDone            !Yes
  410. ?BPTf    "StepFunction"        !Step function?
  411. >beq    RngDone            !Yes
  412. :BiPolar
  413. =Llow     -0.8            !output low-value
  414. :RngDone
  415.  
  416. !    *** Load the Control Strategy and schedules ***
  417. !
  418. =LrnN    MpLC            !end of Self organizing phase
  419. =Llrs    0
  420. ?SMmp    0
  421. >beq    LRS4            !Skip schedules if no mapping
  422.  
  423. =Lctl    "sommap"        !mapping Control Strategy
  424. =RnLm    0            !learn for
  425. +LrnN    5000            !Go on a bit further than SOM phase
  426. !Use default fixed schedules for DBD and EDBD.
  427. ?BPLf    "Delta-Bar-Delta"    !DBD?
  428. >bne    NotDBD2            !Branch to next test if not
  429. =Llrs    "somdbd"        !Fixed schedule
  430. >br    LRS5            !Continue
  431. :NotDBD2
  432. ?BPLf    "Ext DBD"        !EDBD
  433. >bne    LRS5            !Branch if not
  434. =Llrs    "somedbd"            !Fixed schedule
  435. >br    LRS5
  436.  
  437. :LRS4
  438. =Lctl    "somnomap"        !No mapping Control Strategy
  439. =RnLm    4            !learn until
  440.  
  441. :LRS5
  442. @SVsl                !save it back
  443. !
  444. ! Miscellaneous globals
  445. =Grph     1            !Activate instrument list
  446. =jogl    -.1            !lower limit for jog
  447. =jogh    +.1            !upper limit for jog
  448. =seed    257            !starting seed number
  449. @seed                !set the seed
  450. !
  451. ! Recall/Test modes
  452. =RnTm    1
  453. =RnRm    1
  454. !
  455. !
  456. ! Initialize the network
  457. !
  458. @Nini
  459. @EOF
  460.